﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections;





namespace Data.Database
{
    public class Turno
    {  static private String cadenaConexion = ConfigurationManager.ConnectionStrings["Turnet"].ConnectionString; // @"Data Source=|DataDirectory|\BBDD.sdf";
    static private String nombreTabla = "Turnos";
   
        
        public void AnyadirTurno(DataSet turno)
    {
        DataSet dsTurno = new DataSet();
        try
        {
            SqlConnection conexion = new SqlConnection(cadenaConexion);
            String consulta = "Select * from Turnos";
            SqlDataAdapter daTurno = new SqlDataAdapter(consulta, conexion);
            daTurno.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            daTurno.Fill(dsTurno, nombreTabla);
            SqlCommandBuilder cbuilder = new SqlCommandBuilder(daTurno);
            daTurno.Update(turno, "Turnos");

        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }

        public DataSet ConseguirReporte(string id_profesional)
        {
            DataSet dsTurnos = new DataSet();
            
            

            try
            {



                SqlConnection conexion = new SqlConnection(cadenaConexion);
                String consulta = "SELECT CONVERT(VARCHAR, dbo.Turnos.Fecha, 103) AS Fecha, CONVERT(VARCHAR, dbo.Horario.HoraIncio, 108) AS Horario,dbo.Profesional.Apellido + ' ' + dbo.Profesional.Nombre AS Profesional, dbo.Paciente.Apellido + ' ' + dbo.Paciente.Nombre AS Paciente FROM dbo.Turnos INNER JOIN dbo.Horario ON dbo.Turnos.Id_Horario = dbo.Horario.Id_Horario INNER JOIN dbo.Profesional ON dbo.Turnos.Id_Profesional = dbo.Profesional.Id_Profesional INNER JOIN dbo.Paciente ON dbo.Turnos.Id_Paciente = dbo.Paciente.Id_Paciente WHERE dbo.Profesional.Id_Profesional='"+id_profesional+"'";
                SqlDataAdapter daTurnos = new SqlDataAdapter(consulta, conexion);
                daTurnos.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                daTurnos.Fill(dsTurnos, "Turnos"); 
                 
                                
             

                
                
            }

            catch (Exception ex)
            {

            }

            return dsTurnos;

            
        }
        



        public DataSet ObtenerTablaTurno()
        {
            DataSet dsTurnos = new DataSet();

            try
            {
                SqlConnection conexion = new SqlConnection(cadenaConexion);
                String consulta = "SELECT * FROM Turnos";
                SqlDataAdapter daTurnos= new SqlDataAdapter(consulta, conexion);
                daTurnos.MissingSchemaAction = MissingSchemaAction.AddWithKey;
                daTurnos.Fill(dsTurnos, nombreTabla);
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            return dsTurnos;
        }
    }
}
